QuickOPC User's Guide and Reference
Examples - OPC Unified Architecture - Subscribe to a range of elements from an array
// This example shows how to subscribe to range of values from an array.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._UAIndexRangeList
{
    partial class Usage
    {
        public static void Subscribe()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object
            var client = new EasyUAClient();

            Console.WriteLine("Subscribing to range...");
            var attributeArguments = new UAAttributeArguments(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10933")
                {
                    IndexRangeList = UAIndexRangeList.OneDimension(2, 4)
                };
            var monitoredItemArguments = new UAMonitoredItemArguments(attributeArguments, monitoringParameters:1000);
            // The callback is a lambda expression the displays the value
            client.SubscribeMonitoredItem(monitoredItemArguments,
                (sender, eventArgs) =>
                {
                    if (eventArgs.Succeeded)
                    {
                        var arrayValue = eventArgs.AttributeData.Value as Int32[];
                        if (!(arrayValue is null))
                            Console.WriteLine($"Value: {{{String.Join(",", arrayValue)}}}");
                    }
                    else
                        Console.WriteLine($"*** Failure: {eventArgs.ErrorMessageBrief}");
                });

            Console.WriteLine("Processing data change events for 10 seconds...");
            System.Threading.Thread.Sleep(10 * 1000);

            Console.WriteLine("Unsubscribing...");
            client.UnsubscribeAllMonitoredItems();

            Console.WriteLine("Waiting for 2 seconds...");
            System.Threading.Thread.Sleep(2 * 1000);
        }
    }
}
# This example shows how to subscribe to range of values from an array.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


def dataChangeNotification(sender, eventArgs):
    # Display value.
    if eventArgs.Succeeded:
        arrayValue = eventArgs.AttributeData.Value
        print('Value: {', ", ".join(["{}"]*len(arrayValue)).format(*arrayValue), '}', sep='')
    else:
        print('*** Failure: ', eventArgs.ErrorMessageBrief, sep='')


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# Instantiate the client object.
client = EasyUAClient()

print('Subscribing to range...')
attributeArguments = UAAttributeArguments(endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10933'))
attributeArguments.IndexRangeList = UAIndexRangeList.OneDimension(2, 4)
monitoredItemArguments = UAMonitoredItemArguments(attributeArguments, UAMonitoringParameters(1000))
IEasyUAClientExtension.SubscribeMonitoredItem(client,
    monitoredItemArguments,
    EasyUADataChangeNotificationEventHandler(dataChangeNotification))

print('Processing data change events for 10 seconds...')
time.sleep(10)

print('Unsubscribing...')
client.UnsubscribeAllMonitoredItems()

print('Waiting for 2 seconds...')
time.sleep(2)

print('Finished.')

 

See Also

Conceptual

Examples - Reactive Programming